﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using Volo.Abp;
using Volo.Abp.Domain.Values;

namespace Mozhi.Abp.Domain.BasicData
{
    public class Product : ValueObject
    {
        [JsonProperty]
        public virtual Guid Id { get; protected set; }

        [JsonProperty]
        public virtual string Name { get; protected set; }

        [JsonProperty]
        public virtual string Code {  get; protected set; }

        [JsonProperty]
        public virtual bool Activated { protected set; get; }

        [JsonProperty]
        public virtual int Type { get; protected set; }

        [JsonProperty]
        public virtual bool Saleable { get; protected set; }

        [JsonProperty]
        public virtual bool Purchasable { get; protected set; }

        /// <summary>
        /// 可生产的
        /// </summary>
        [JsonProperty]
        public virtual bool Producible { get; protected set; }

        //可生产的
        [JsonProperty]
        public virtual bool Outsourceable { get; protected set; }

        /// <summary>
        /// 可资产
        /// </summary>
        [JsonProperty]
        public virtual bool Assetable { get; protected set; }

        /// <summary>
        /// 基本单位
        /// </summary>
        [JsonProperty]
        public virtual Guid BasicUnitId { get; protected set; }

        /// <summary>
        /// 规格
        /// </summary>
        [JsonProperty]
        public virtual string Model‌ { get; protected set; }

        [JsonProperty]
        public virtual Guid? DefatultTaxRateId { get; protected set; }

        [JsonProperty]
        public virtual Guid? DefaultSupplierId { get; protected set; }

        private Product() { }

        public virtual void Validate()
        {
            if (!Activated)
                throw new UserFriendlyException($"产品:{Code}-{Name}已禁用", "100000");
        }


        protected override IEnumerable<object> GetAtomicValues()
        {
            yield return Id;
            yield return Name;
            yield return Activated;
        }
    }
}
